package ar.gov.hackaton.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ar.gov.hackaton.model.Poblacion;

@Repository
public class PoblacionDao {
	@PersistenceContext
	private EntityManager entityManager;

	public Poblacion find(Long id) {
		return entityManager.find(Poblacion.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<Poblacion> getPeople() {
		return entityManager.createQuery("select p from Person p").getResultList();
	}

	@Transactional
	public Poblacion save(Poblacion person) {
		if (person.getId() == null) {
			entityManager.persist(person);
			return person;
		} else {
			return entityManager.merge(person);
		}
	}
}
